package com.feng.controller.back;

import com.feng.dto.CategoryDto;
import com.feng.entity.Category;
import com.feng.service.NewscategoryService;
import com.feng.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 丰
 * @date: 2023/1/1 17:02
 */
@RestController
@RequestMapping("/back/newscategory")
@Api(tags = "后台新闻分类接口")
public class NewsCategoryController {

    @Autowired
    private NewscategoryService newscategoryService;

    @ApiOperation("添加分类")
    @PutMapping("/add")
    public ResultVo<Integer> add(@RequestBody CategoryDto categoryDto){
        return newscategoryService.add(categoryDto);
    }

    @ApiOperation("批量删除分类")
    @DeleteMapping("/deleteAll")
    public ResultVo<Integer> deleteAll(@RequestBody Integer[] ids){
        return newscategoryService.deleteAll(ids);
    }

    @ApiOperation("根据id删除分类")
    @DeleteMapping("/delete/{id}")
    public ResultVo<Integer> delete(@PathVariable("id") Integer id){
        return newscategoryService.deleteById(id);
    }

    @ApiOperation("根据id查询分类")
    @GetMapping("/findById/{id}")
    public ResultVo<Category> findById(@PathVariable("id") Integer id){
        return newscategoryService.findById(id);
    }

    @ApiOperation("查询分类")
    @GetMapping("/getList")
    public ResultVo<List<CategoryDto>> getList(){
        return newscategoryService.getList();
    }

    @ApiOperation("跟新分类")
    @PostMapping("/update")
    public ResultVo<Integer> update(@RequestBody Category category){
        return newscategoryService.update(category);
    }
}
